cmake_minimum_required(VERSION 3.20)

mark_as_advanced(SIMPLEMEDIA_VERSION)
set(SIMPLEMEDIA_VERSION 1.0.0)

project(simplemedia
    VERSION ${SIMPLEMEDIA_VERSION}
    LANGUAGES CXX
)

# configure
######################################################################
option(SIMPLEMEDIA_EXAMPLE_GEN "Generate examples" ON)

include(CMakeDependentOption)
include(GNUInstallDirs)


# libraries
######################################################################
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(FFmpeg REQUIRED)


# header
######################################################################
mark_as_advanced(simplemedia_include_dirs)

list(APPEND simplemedia_include_dirs ${FFMPEG_INCLUDE_DIRS})
list(APPEND simplemedia_include_dirs "${simplemedia_SOURCE_DIR}/include")

include_directories(${simplemedia_include_dirs})


# source file
######################################################################
mark_as_advanced(simplemedia_srcs)

aux_source_directory(${simplemedia_SOURCE_DIR}/src simplemedia_srcs)


# simplemedia generate
######################################################################
add_library(${PROJECT_NAME} STATIC ${simplemedia_srcs})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}"
        CLEAN_DIRECT_OUTPUT 1
)

mark_as_advanced(__simplemedia_opensource_libraries)
list(APPEND __simplemedia_opensource_libraries ${FFMPEG_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${__simplemedia_opensource_libraries} pthread)


# add subdirectory
######################################################################
mark_as_advanced(__simplemedia_include_dir)
foreach(__simplemedia_include_dir ${simplemedia_include_dirs})
  target_include_directories(
    simplemedia SYSTEM
    INTERFACE
      "$<BUILD_INTERFACE:${__simplemedia_include_dir}>"
      "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endforeach()

if (SIMPLEMEDIA_EXAMPLE_GEN)
    # RTSP stream
    add_executable(example-rtsp-stream ${simplemedia_SOURCE_DIR}/example/example-rtsp-stream.cc)
    target_link_libraries(example-rtsp-stream simplemedia pthread dl)
endif()
